<!-- 显示所有 completed: true 的任务列表 -->
<template>
  <div class="completed-tasks">
    <div class="back-button-container">
      <button @click="goBackToHome" class="back-button">
        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
          <path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8z"/>
        </svg>
        返回首页
      </button>
    </div>
    
    <h2>已完成任务</h2>
    
    <div v-if="completedTasks.length === 0" class="empty-state">
      <p>暂无已完成任务</p>
    </div>
    
    <div v-else>
      <div class="task-list">
        <TaskCard 
          v-for="task in completedTasks" 
          :key="task.id" 
          :task="task" 
          @taskToggled="toggleTaskStatus"
          @taskDeleted="deleteTask"
          @taskEdited="editTask"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useTaskStore } from '../store/taskStore';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import TaskCard from '../components/TaskCard.vue';

const taskStore = useTaskStore();
const router = useRouter();

// 从Store获取响应式已完成任务列表
const completedTasks = taskStore.completedTasks;

const toggleTaskStatus = (id: string) => {
  taskStore.toggleTaskStatus(id);
};

const deleteTask = (id: string) => {
  taskStore.deleteTask(id);
};

const editTask = (taskId: string) => {
  router.push(`/task/${taskId}`);
};

const goBackToHome = () => {
  router.push('/');
};
</script>
<!-- 显示所有 completed: true 的任务列表 -->
<style scoped>
.completed-tasks {
  margin-top: 2rem;
}

h2 {
  margin-bottom: 1rem;
  color: #4a6cf7;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.back-button-container {
  margin-bottom: 1.5rem;
}

.back-button {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: #f0f2ff;
  color: #4a6cf7;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background-color 0.3s;
}

.back-button svg {
  margin-right: 0.5rem;
}

.back-button:hover {
  background-color: #e0e6ff;
}
</style>